package com.juc.learn.set;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * ClassName:ThreadDemo
 * Package:com.juc.learn.set
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/27 - 9:09
 * @Version:v1.0
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //Set<String> sets = new HashSet<>();//有线程安全问题
        Set<String> sets=new CopyOnWriteArraySet<>();
        for (int i = 0; i < 150; i++) {
            new Thread(()->{
                sets.add(UUID.randomUUID().toString().substring(0,4));
                System.out.println(sets);
            }).start();
        }
    }
}
